﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
    WebDBDataContext db = new WebDBDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        //Disable All the Shipping Information (Non Editable Region)

        ShipTextBoxContact.Enabled = false;
        ShipTextBoxAdd1.Enabled = false;
        ShipTextBoxAdd2.Enabled = false;
        ShipTextBoxTownCity.Enabled = false;
        ShipTextBoxState.Enabled = false;
        ShipTextBoxZipCode.Enabled = false;
        ShipComboBoxCountry.Enabled = false;
        ShipTextBoxPhone.Enabled = false;
        ShipTextBoxMobile.Enabled = false;
        ShipTextBoxEmail.Enabled = false;

        //Disable All the Validation Part of Shipping Information

        RequiredFieldValidatorContact.Enabled = false;
        RequiredFieldValidatorAdd1.Enabled = false;
        RequiredFieldValidatorAdd2.Enabled = false;
        RequiredFieldValidatorTownCity.Enabled = false;
        RequiredFieldValidatorZipCode.Enabled = false;
        RequiredFieldValidatorCountry.Enabled = false;
        RequiredFieldValidatorPhoneNo.Enabled = false;
        RequiredFieldValidatorMobileNo.Enabled = false;
        RequiredFieldValidatorEmail.Enabled = false;
        RegularExpressionValidatorEmailVal.Enabled = false;
        RegularExpressionValidatorMobileNoNumber.Enabled = false;
        RegularExpressionValidatorPhoneNumberOnly.Enabled = false;
        RegularExpressionValidatorZipNumber.Enabled = false;


    }
    protected void ButtonRegister_Click(object sender, EventArgs e)
    {
        Tbl_Distributor dis = new Tbl_Distributor();
        
        //Import Data from the registration form
        try
        {
            dis.Dis_ID = TextBoxDisID.Text;
            dis.Sup_ID = TextBoxSuperID.Text;
            dis.Title = ComboBoxTitle.Text;
            dis.Sur_Name = TextBoxSurName.Text;
            dis.Giv_Name = TextBoxGivenName.Text;
            dis.Che_Name = TextBoxChequeName.Text;
            dis.Address1 = TextBoxAdd1.Text;
            dis.Address2 = TextBoxAdd2.Text;
            dis.City = TextBoxTownCity.Text;
            dis.Province = TextBoxState.Text;
            dis.Zip_Code = int.Parse(TextBoxZipCode.Text);
            dis.Country = ComboBoxCountry.Text;
            dis.Hom_Tel_No = TextBoxHomePhone.Text;
            dis.Mob_No = TextBoxMobileNo.Text;
            dis.Email = TextBoxEmail.Text;
            dis.Ship_Contact = ShipTextBoxContact.Text;
            dis.Ship_Address1 = ShipTextBoxAdd1.Text;
            dis.Ship_Address2 = ShipTextBoxAdd2.Text;
            dis.Ship_City = ShipTextBoxTownCity.Text;
            dis.Ship_Province = ShipTextBoxState.Text;
            dis.Ship_Country = ShipComboBoxCountry.Text;
            dis.Ship_Hom_Tel_No = ShipTextBoxPhone.Text;
            dis.Ship_Mob_No = ShipTextBoxMobile.Text;
            dis.Ship_Email = ShipTextBoxEmail.Text;
            dis.ID_Type = ComboBoxValidIDType.Text;
            dis.ID_No = TextBoxValidIDNo.Text;
            dis.Nationality = TextBoxNationality.Text;
            dis.Dob = DatePickerDOB.ToString();
            dis.Occupation = TextBoxOccupation.Text;
            dis.Bussiness_NameAdd = TextBoxNameofBusiness.Text;
            dis.Office_Tel = TextBoxOfficeNo.Text;
            dis.Beneficiary = BenTextBoxName.Text;
            dis.Ben_Rel = BenComboBoxRelationship.Text;
            dis.Ben_Add = BenTextBoxAdd.Text;
            dis.Nominee = NomTextBoxName.Text;
            dis.Nom_Rel = NomComboBoxRelationship.Text;
            dis.Nom_Add = NomTextBoxAdd.Text;
            dis.Sec_Question = ComboBoxSecurityQ.Text;
            dis.Answer = TextBoxSA.Text;
            dis.Sec_Word = TextBoxSW.Text;
            dis.Qa_Pin = int.Parse(TextBoxQAPin.Text);
            dis.Pas_Word = TextBoxPass.Text;
            dis.Web_Url = TextBoxURL.Text;

            db.Tbl_Distributors.InsertOnSubmit(dis);
            db.SubmitChanges();

            //Display a lable saying that the registration is Successfull !

            LabelMessage.Text = "Your Details are Successfully Inserted !";
        }
        catch (Exception) 
        {
            //Display a lable saying that the registration is not Done !

            LabelMessageError.Text = "Your Details Cannot be inserted !";
        }
        }

    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        if (!CheckBox1.Checked)
        {
            //Enable All the Shipment information after the check box is CHECKED !

            ShipTextBoxContact.Enabled = true;
            ShipTextBoxAdd1.Enabled = true;
            ShipTextBoxAdd2.Enabled = true;
            ShipTextBoxTownCity.Enabled = true;
            ShipTextBoxState.Enabled = true;
            ShipTextBoxZipCode.Enabled = true;
            ShipComboBoxCountry.Enabled = true;
            ShipTextBoxPhone.Enabled = true;
            ShipTextBoxMobile.Enabled = true;
            ShipTextBoxEmail.Enabled = true;

            //Enable All the Validation Part of the Shipping Information

            RequiredFieldValidatorContact.Enabled = true;
            RequiredFieldValidatorAdd1.Enabled = true;
            RequiredFieldValidatorAdd2.Enabled = true;
            RequiredFieldValidatorTownCity.Enabled = true;
            RequiredFieldValidatorZipCode.Enabled = true;
            RequiredFieldValidatorCountry.Enabled = true;
            RequiredFieldValidatorPhoneNo.Enabled = true;
            RequiredFieldValidatorMobileNo.Enabled = true;
            RequiredFieldValidatorEmail.Enabled = true;
            RegularExpressionValidatorEmailVal.Enabled = true;
            RegularExpressionValidatorMobileNoNumber.Enabled = true;
            RegularExpressionValidatorPhoneNumberOnly.Enabled = true;
            RegularExpressionValidatorZipNumber.Enabled = true;
           
        }
    }
}